import Vue from 'vue'
import VueRouter from 'vue-router'
import SystemView from "@/views/system.vue";
import IndexView from '@/views/index.vue';
import IndexView2 from "@/views/index2.vue";
import Login from "@/views/login.vue";
import Payment1 from "@/views/payment1.vue";
import Payment2 from "@/views/payment2.vue";
import Advent from "@/views/summarize/advent.vue";
import GChannel from "@/views/summarize/gChannel.vue";
import OfflineFee from "@/views/summarize/offlineFee.vue";
import OnlineFee from "@/views/summarize/onlineFee.vue";
import PaymentSuccess from "@/views/paymentSuccess.vue";
import GreenChannel from "@/views/greenChannel.vue";
import GreenChannelOK from "@/views/greenChannelOK.vue";
import TotalFee from "@/views/summarize/totalFee.vue";
import PersonalInfo from "@/views/personalInfo.vue";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'login',
        component: Login,
        meta: {
            menu: 'myMenu',
            title: 'Login Page'
        }
    },
    {
        path: '/system',
        name: 'system',
        component: SystemView,
        meta: {
            menu: 'myMenu',
            title: 'System Page'
        }
    },
    {
        path: '/index',
        name: 'index',
        component: IndexView,
        meta: {
            menu: 'myMenu',
            title: 'Index Page'
        }
    },
    {
        path: '/index2',
        name: 'index2',
        component: IndexView2,
        meta: {
            menu: 'myMenu2',
            title: 'Index2 Page'
        }
    },
    {
        path: '/personalInfo',
        name: 'personalInfo',
        component: PersonalInfo,
        meta: {
            menu: 'myMenu2',
            title: 'PersonalInfo Page'
        }
    },
    {
        path: '/payment1',
        name: 'payment',
        component: Payment1,
        meta: {
            menu: 'myMenu2',
            title: 'OnlinePayment Page'
        }
    },
    {
        path: '/payment2',
        name: 'payment',
        component: Payment2,
        meta: {
            menu: 'myMenu2',
            title: 'OfflinePayment Page'
        }
    },
    {
        path: '/advent',
        name: 'advent',
        component: Advent,
        meta: {
            menu: 'myMenu2',
            title: 'Advent Page'
        }
    },
    {
        path: '/paymentSuccess',
        name: 'paymentSuccess',
        component: PaymentSuccess,
        meta: {
            menu: 'myMenu2',
            title: 'PaymentSuccess Page'
        }
    },
    {
        path: '/greenChannel',
        name: 'greenChannel',
        component: GreenChannel,
        meta: {
            menu: 'myMenu2',
            title: 'GreenChannel Page'
        }
    },
    {
        path: '/greenChannelOK',
        name: 'greenChannelOK',
        component: GreenChannelOK,
        meta: {
            menu: 'myMenu2',
            title: 'GreenChannelOK Page'
        }
    },
    {
        path: '/gChannel',
        name: 'gChannel',
        component: GChannel,
        meta: {
            menu: 'myMenu2',
            title: 'G Channel Page'
        }
    },
    {
        path: '/offlineFee',
        name: 'offlineFee',
        component: OfflineFee,
        meta: {
            menu: 'myMenu2',
            title: 'Offline Fee Page'
        }
    },
    {
        path: '/onlineFee',
        name: 'onlineFee',
        component: OnlineFee,
        meta: {
            menu: 'myMenu2',
            title: 'Online Fee Page'
        }
    },
    {
        path: '/totalFee',
        name: 'totalFee',
        component: TotalFee,
        meta: {
            menu: 'myMenu2',
            title: 'Total Fee Page'
        }
    },
    {
        path: '/login',
        name: 'login',
        component: Login,
        meta: {
            menu: 'myMenu2',
            title: 'Login Page'
        }
    },
    {
        path: '/department',
        name: 'Department',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Department.vue'),
        meta: {
            title: 'Department Page'
        }
    },
    {
        path: '/office',
        name: 'Office',
        component: () => import(/* webpackChunkName: "about" */ '../views/Office.vue'),
        meta: {
            title: 'Office Page'
        }
    },
    {
        path: '/receiveAndQuery',
        name: 'ReceiveAndQuery',
        component: () => import(/* webpackChunkName: "about" */ '../views/ReceiveAndQuery.vue'),
        meta: {
            title: 'Receive and Query Page'
        }
    },
    {
        path: '/buyBook',
        name: 'BuyBook',
        component: () => import(/* webpackChunkName: "about" */ '../views/BuyBook.vue'),
        meta: {
            title: 'Buy Book Page'
        }
    },
    {
        path: '/textbookChange',
        name: 'TextbookChange',
        component: () => import(/* webpackChunkName: "about" */ '../views/TextbookChange.vue'),
        meta: {
            title: 'Textbook Change Page'
        }
    },
    {
        path: '/textbookInventory',
        name: 'TextbookInventory',
        component: () => import(/* webpackChunkName: "about" */ '../views/TextbookInventory.vue'),
        meta: {
            title: 'Textbook Inventory Page'
        }
    },
    {
        path: '/textbookStockChange',
        name: 'TextbookStockChange',
        component: () => import(/* webpackChunkName: "about" */ '../views/TextbookStockChange.vue'),
        meta: {
            title: 'Textbook Stock Change Page'
        }
    },
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
    return routerReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
    // 设置页面标题
    if (to.meta && to.meta.title) {
        document.title = to.meta.title;
    } else {
        document.title = 'Default Title'; // 默认标题
    }
    next();
});

export default router
